package com.hisense.ovcloud.mqtt.business.routers;

import com.hisense.ovcloud.commons.configs.validator.BaseRouterConfiguration;
import com.hisense.ovcloud.mqtt.business.service.AuthService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@Configuration
public class RoutingConfiguration extends BaseRouterConfiguration {

    private final AuthService authService;

    public RoutingConfiguration(AuthService authService) {
        this.authService = authService;
    }


    @Bean
    public RouterFunction<ServerResponse> authRoutes() {
        return RouterFunctions.nest(path("/"),
                route()
                    .POST("/mqttHook", authService::handleGetHook)
                    .POST("/getWifiStats", authService::handleGetWifiStats)
                    .POST("/getDeviceInfo", authService::handleGetWifiStats)
                    .POST("/setCmd", authService::handleSetCmd)
                    .POST("/getSecretKey", authService::handleGetSecretKey)
                    .POST("/notifyWifiOnlineStatusToHitachi", authService::handlenNotifyWifiOnlineStatusToHitachi)
                    .build());
    }
}

